var express = require('express');
var router = express.Router();

var passportLinkedIn = require('../auth/linkedin')
var passportLinkedIn2 = require('../auth/linkedin2')
const passportGithub = require('../auth/github')
const passportWeixin = require('../auth/weixin')


router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

router.get('/login', function(req, res, next) {
  res.send('Go back and register!')
})

// router.get('/auth/linkedin', passportLinkedIn.authenticate('linkedin'))

// router.get('/auth/linkedin/callback',
//   passportLinkedIn.authenticate('linkedin', { failureRedirect: '/login' }),
//   function(req, res) {
//     res.json(req.user)
//   }  
// )


router.get('/auth/linkedin', passportLinkedIn2.authenticate('linkedin', { state: 'SOME STATE'  }),
  function(req, res){
    // The request will be redirected to LinkedIn for authentication, so this
    // function will not be called.
  });

router.get('/auth/linkedin/callback', 
  passportLinkedIn2.authenticate('linkedin', { failureRedirect: '/login' }),
  function(req, res) {
    console.log(req.user)
    res.redirect('/')
  }
);


router.get('/auth/github', passportGithub.authenticate('github', { state: 'SOME STATE'  }),
  function(req, res){
    // The request will be redirected to LinkedIn for authentication, so this
    // function will not be called.
  });

router.get('/auth/github/callback', 
  passportGithub.authenticate('github', { failureRedirect: '/login' }),
  function(req, res) {
    console.log(req.user)
    res.redirect('/')
  }
);

router.get('/auth/weixin', passportWeixin.authenticate('weixin', {state: '3e641e4cb971f31c1f358e8b21fb695f'}), (req, res) => {})

router.get('/third/login/weixin',
  passportWeixin.authenticate('weixin', {failureRedirect: '/login'}),
  function (req, res) {
    console.log(req.user)
    res.redirect('/')
  })


module.exports = router;
